const Actions = require('./actions');
const DB = require('app/db');
import { Storage } from 'clientConfig/util/StoreData'
module.exports = Reflux.createStore({
    listenables: [Actions],
    data: {

    },
    onFetchAwardList: function (pageNum, props, success, error) {
        let t = this;
        DB.Parent.get_award_lists({
            schoolId: Storage.get('user.schoolId')||'f20171120',
            studentId: Storage.get('user.studentId')||'24900',
            pageIndex: pageNum
        })
            .then((content) => {
                let schoolId = content.check.schoolId;
                let classId = content.check.classId;
                let teacherId = content.check.teacherId;
                content = content.data.list;
                var list = [];
                var obj = {};
                if (content && content.length > 0) {
                    for (let item of content) {
                        obj["schoolId"] = schoolId;
                        obj["studentId"] = item.studentId;
                        obj["badge"] = false;
                        obj["title"] = item.title;
                        obj["subtitle"] = item.time;
                        obj["awardId"] = item.id;
                        obj["msg"] = item.msg;
                        list.push(obj);
                        obj = {};
                    }
                }
                const hasNoMore = list.length < props.pageSize;
                t.data.listData = list;
                if (success)
                    success(hasNoMore, list);
            })
            .catch(function (error) {

            });
    },
    updateComponent: function () {
        this.trigger(this.data);
    }
});
